package org.iron.services;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.json.JSONObject;
import org.iron.entities.Book;

import com.jcabi.http.request.JdkRequest;

public class NewBookServiceImpl implements NewBookService
{

    @Override
    public List<Book> getNewBooks()
    {
        List<Book> list = new ArrayList<Book>();

        JSONObject json = null;
        String data = null;
        try
        {
            data = new JdkRequest("https://api.douban.com/v2/book/isbn/9787115205803?fields=images").uri().back().fetch().body();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        json = new JSONObject(data);

        String url = json.getJSONObject("images").getString("medium");

        Book book = new Book();
        book.setPhoto(url);
        list.add(book);

        // TODO Auto-generated method stub
        return list;
    }

}
